package com.ss.android.article.share.ui;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;

import java.lang.ref.WeakReference;

public class RecyclerViewWrapper extends HorizontalScrollView {
    public static abstract class a {
        boolean a;
        WeakReference b;

        public a() {
            this.a = true;
        }

        public abstract int a();

        public abstract d a(ViewGroup arg1);

        public abstract void a(d arg1, int arg2);

        public final void b() {
            int v10 = -2;
            Object v2 = this.b == null ? null : this.b.get();
            if (v2 != null) {
                if (((RecyclerViewWrapper) v2).getParent() == null) {
                    this.a = true;
                } else {
                    this.a = false;
                    ((RecyclerViewWrapper) v2).removeAllViews();
                    LinearLayout v3 = new LinearLayout(((RecyclerViewWrapper) v2).getContext());
                    v3.setOrientation(LinearLayout.HORIZONTAL);
                    ((RecyclerViewWrapper) v2).addView(((View) v3), new ViewGroup.LayoutParams(v10, -1));
                    int v4 = this.a();
                    Rect v5 = new Rect();
                    c v6 = new c();
                    int v0;
                    for (v0 = 0; v0 < v4; ++v0) {
                        d v1 = this.a(((ViewGroup) v3));
                        v1.d = v0;
                        this.a(v1, v0);
                        LinearLayout.LayoutParams v7 = new LinearLayout.LayoutParams(v10, v10);
                        if (((RecyclerViewWrapper) v2).a != null) {
                            v6.a = v4;
                            ((RecyclerViewWrapper) v2).a.a(v5, v1.c, v6);
                            v7.leftMargin = v5.left;
                            v7.topMargin = v5.top;
                            v7.rightMargin = v5.right;
                            v7.bottomMargin = v5.bottom;
                        }

                        v3.addView(v1.c, ((ViewGroup.LayoutParams) v7));
                    }
                }
            }
        }
    }

    public static abstract class b {
        public b() {

        }

        public void a(Rect arg1, View arg2, c arg3) {
        }
    }

    public static final class c {
        public int a;

        public c() {

        }
    }

    public static abstract class d {
        public final View c;
        public int d;

        public d(View arg1) {

            this.c = arg1;
        }
    }

    b a;
    private a b;

    public RecyclerViewWrapper(Context arg1) {
        super(arg1);
        this.a();
    }

    public RecyclerViewWrapper(Context arg1, AttributeSet arg2) {
        super(arg1, arg2);
        this.a();
    }

    public RecyclerViewWrapper(Context arg1, AttributeSet arg2, int arg3) {
        super(arg1, arg2, arg3);
        this.a();
    }

    @TargetApi(value = 21)
    public RecyclerViewWrapper(Context arg1, AttributeSet arg2, int arg3, int arg4) {
        super(arg1, arg2, arg3, arg4);
        this.a();
    }

    public final void a(b arg2) {
        if (this.a == arg2) {
            this.a = null;
        }
    }

    private void a() {
        this.setHorizontalScrollBarEnabled(false);
        this.setVerticalScrollBarEnabled(false);
    }

    public final void b(b arg3) {
        if (this.a != null && this.a != arg3) {
            throw new IllegalStateException("Wrapper supports only 1 ItemDecoration.");
        }

        this.a = arg3;
        if (this.b != null) {
            this.b.b();
        }
    }

    public a getAdapter() {
        return this.b;
    }

    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (this.b != null && (this.b.a)) {
            this.b.b();
        }
    }

    public void setAdapter(a arg3) {
        this.b = arg3;
        this.b.b = new WeakReference(this);
    }
}

